package org.wzl.todolisthelper.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wzl.todolisthelper.service.ProfileService;
import org.wzl.todolisthelper.utils.Resp;
import org.wzl.todolisthelper.vo.UserUpdateDTO;
import org.wzl.todolisthelper.vo.UserVO;

import java.util.Map;

/**
 * 用户信息controller
 */
@Slf4j
@RestController
@RequestMapping("/profile")
public class ProfileController {

    @Resource
    private ProfileService profileService;

    /**
     * 获取当前用户信息
     */
    @GetMapping("/getUserInfo")
    public Resp<UserVO> getUserInfo() {
        UserVO userVO = profileService.getUserInfo();
        return Resp.ok(userVO);
    }

    /**
     * 上传用户头像
     */
    @PostMapping("/uploadAvatar")
    public Resp<String> uploadAvatar(@RequestBody Map<String, String> map) {
        profileService.uploadAvatar(map.get("file"));
        return Resp.ok("上传成功");
    }

    /**
     * 更新用户信息
     */
    @PostMapping("/update")
    public Resp<?> update(@RequestBody UserUpdateDTO userUpdateDTO) {
        profileService.update(userUpdateDTO);
        return Resp.ok();
    }

}
